import { isObjct } from "../../until.js";
import { reactive } from "../ractive";
import { tigger } from "../ractive/tigger.js";
import { track } from "../ractive/track.js";

const isReactive = (val) => (isObjct(val) ? reactive(val) : val); // 对象采用reactive代理

export class refImpl {
  constructor(rawValue) {
    this._rawValue = rawValue;
    this._v_isRef = true;
    this._value = isReactive(rawValue);
  }
  get value() {
    track(this, "value");
    return this._value;
  }
  set value(newValue) {
    if (newValue !== this._value) {
      this._rawValue = newValue;
      this._value = isReactive(newValue);
      tigger(this, "value");
    }
  }
}
